perf(compiler): optimize vector arithmetic and numeric loop type inference#2237
perf(compiler): optimize vector arithmetic and numeric loop type inference#2237ActualMasterOogway wants to merge 3 commits intoluau-lang:masterfrom
Conversation
- Relax commutative swap optimization in compileExprBinary to include LBC_TYPE_VECTOR. - Implement visit(AstStatFor) in TypeMapVisitor to correctly infer numeric type for loop variables. Fixes luau-lang#2235
| bytecode.emitABC(getBinaryOpArith(expr->op, /* k= */ true), target, rr, uint8_t(lc)); | ||
|
|
||
| hintTemporaryExprRegType(expr->right, rr, LBC_TYPE_NUMBER, /* instLength */ 1); | ||
| hintTemporaryExprRegType(expr->right, rr, *ty, /* instLength */ 1); |
There was a problem hiding this comment.
| hintTemporaryExprRegType(expr->right, rr, *ty, /* instLength */ 1); | |
| hintTemporaryExprRegType(expr->right, rr, LBC_TYPE_NUMBER, /* instLength */ 1); |
Hint system is used to provide hints on types that are not the expected operands of an instruction.
By saying that 'vector' is expected for an add/mul, hint will not be generated and this will cause jit performance to regress on a wrong type speculation.
For example in this case:
local function foo(t: {a: vector})
return 2 * t.a
endWith this change, the fast-path is generated for number*number, causing a fallback to be taken at runtime.
Since this was a regression not caught by existing tests, this example should be added as a regression test to IrLowering.test.cpp
vegorov-rbx
left a comment
There was a problem hiding this comment.
PR says that it is making an improvement with an additional optimization.
While that is true, not a single test case has been added to cover this improvement and show that it is working.
New tests should be placed in Compiler.test.cpp
vegorov-rbx
left a comment
There was a problem hiding this comment.
These changes have to be flagged to be accepted: https://github.com/luau-lang/luau/blob/master/CONTRIBUTING.md#feature-flags
|
Thank you for providing an improvement. With a few changes it will get to a form we can merge. |
This PR improves the compiler's ability to optimize arithmetic expressions, specifically targeting vector operations and numeric
forloops. By improving type inference, we can now apply better optimizations in more places.Closes #2235